//
//  LoaderView.m
//  MVVM-ViewModel-NetWork-Model
//
//  Created by 刘小椿 on 16/11/11.
//  Copyright © 2016年 刘小椿. All rights reserved.
//

#import "XCLoaderView.h"

@interface XCLoaderView()

@property (nonatomic,strong) UIImageView* loaderImageview;
@property (nonatomic,strong) UILabel* lable;

@end

@implementation XCLoaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)addAnimation
{
    
    [self addSubview:self.loaderImageview];
    [self addSubview:self.lable];
    NSArray* images = @[[UIImage imageNamed:@"one"],
                        [UIImage imageNamed:@"two"],
                        [UIImage imageNamed:@"three"],
                        [UIImage imageNamed:@"four"],
                        [UIImage imageNamed:@"five"],
                        [UIImage imageNamed:@"six"],
                        [UIImage imageNamed:@"seven"],
                        [UIImage imageNamed:@"eight"]
                        ];
    self.loaderImageview.animationImages = images;
    self.loaderImageview.animationRepeatCount = 100000;
    self.loaderImageview.animationDuration = 1;
    [self.loaderImageview startAnimating];
}

- (void)stopAnimation
{
    if (self.loaderImageview.isAnimating) {
        [self.loaderImageview stopAnimating];
    }
}

#pragma mark --Set/Get
- (UIImageView *)loaderImageview
{
    if (!_loaderImageview) {
        _loaderImageview = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 - 35, self.frame.size.height / 2 - 25, 70, 50)];
    }
    return _loaderImageview;
}

- (UILabel *)lable
{
    if (!_lable) {
        _lable = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 - 60,self.frame.size.height / 2 + 25, 120, 30)];
        _lable.textColor = [UIColor colorWithRed:128/255.0 green:128/255.0 blue:128/255.0 alpha:1];
        _lable.font = [UIFont systemFontOfSize:14];
        _lable.textAlignment = NSTextAlignmentCenter;
        _lable.text = @"加载中...";
    }
    return _lable;
}

@end
